<template>
	<view class="page">
    <u-subsection :list="list" :current="curNow" @change="sectionChange"></u-subsection>
    <view  v-for="(item,index) in recycleList"  :key="index" >
      <view carBox-item style="position: relative; padding: 10px 10px; border: 1px solid #4d4640;border-radius: 20px;margin: 10px 10px;" >
						  <view>
                <view style="margin-top: 3px;">预约日期{{ item.dataSpan }}</view>
                <view style="margin-top: 3px;">预约时间{{ item.timeSpan }}</view>
                <view  style="margin-top: 3px;" >姓名{{item.ordername}}</view>
							  <view style="margin-top: 3px;">电话{{ item.phone }}</view>
                <view style="margin-top: 3px;">地址{{ item.address }}</view>
                <button v-if="curNow ==0" style="position: absolute;top: 0;right: 0;width: 100px;border-radius: 20px;margin-top: 20px;" @click="goSure(item)">确认完成</button>
                <button v-if="curNow ==1" style="position: absolute;top: 0;right: 0;width: 100px;border-radius: 20px;margin-top: 20px;" @click="goAfter()">问题反馈</button>
						  </view>
        </view>
    </view>
	</view>
</template>

<script>
import {baseUrl} from '@/config'
export default {

	data() {
		return {
      workDoller:0,
      workId:0,
      id:0,
      doller:0,
      userId:'',
      list: ['待上门', '已完成'],
      curNow: 0,
      status:0,
      recycleList:[]
		};
	},
  beforeCreate(){
  
      uni.request({
              url: baseUrl+'/v1/recycle/orderAdminSearch',
              data:{
                status:1
              },
              success: (res) => {
                this.recycleList = res.data.data
                }
          });
          
    
  },
	onShow() {
    // this.userId = uni.getStorageSync('user').data[0].userId
    this.getRecycleList()
  },
	
	methods: {
    goAfter(){
      uni.navigateTo({
        url:'/pages/after/index'
      })
    },
    goOff(item){
      uni.request({
              url: baseUrl+'/v1/recycle/orderDelete',
              data:{
                id:item.id
              },
              success: () => {
              this.getRecycleList()
              }
          });
    },
    goSure(item){

      this.workId = uni.getStorageSync('user').data[0].id
      uni.request({
            method: 'GET',
                  url: baseUrl+'/v1/user/idSearch',
                  data:{
                    id: this.workId,
                    },
                  success: (res) => {
                    this.workDoller = res.data.data[0].doller
                    uni.request({
                      method: 'POST',
                            header: {
                              'Content-Type': 'application/x-www-form-urlencoded'
                            },
                            url: baseUrl+'/v1/user/userUpdate',
                            data:{
                                id : this.workId,
                                doller : parseInt(this.workDoller)+10
                            },
                            success: () => {
                              this.getRecycleList()
                              }
                        });
                    }
              });

      uni.request({
        method: 'POST',
              header: {
                'Content-Type': 'application/x-www-form-urlencoded'
              },
              url: baseUrl+'/v1/recycle/orderUpdate',
              data:{
                id : item.id,
                status : parseInt(item.status)+1
              },
              success: () => {
                uni.request({
                  method: 'GET',
                        url: baseUrl+'/v1/recycle/orderIdSearch',
                        data:{
                          id : item.id,
                        },
                        success: (res) => {
                          this.userId = res.data.data[0].userId
                          uni.request({
                            method: 'GET',
                                  url: baseUrl+'/v1/user/userIdSearch',
                                  data:{
                                    userId: this.userId,
                                  },
                                  success: (res) => {
                                    this.doller = res.data.data[0].doller
                                    this.id = res.data.data[0].id
                                              uni.request({
                                                      method: 'POST',
                                                            header: {
                                                              'Content-Type': 'application/x-www-form-urlencoded'
                                                            },
                                                            url: baseUrl+'/v1/user/userUpdate',
                                                            data:{
                                                              id : this.id,
                                                              doller : parseInt(this.doller)+50
                                                            },
                                                            success: () => {
                                                              this.getRecycleList()
                                                              }
                                                        });
                                    }
                              });
                          }
                    });
                }
          });
      


    },
    sectionChange(index) {
				this.curNow = index;
        this.status = this.curNow+1
        this.getRecycleList()
			},
    getRecycleList(){
      uni.request({
              url: baseUrl+'/v1/recycle/orderAdminSearch',
              data:{
                status:this.status
              },
              success: (res) => {
                if(res.data.code == 200){
                  this.recycleList = res.data.data
                }else{
                  this.recycleList = []
                }
                }
          });
          
    }
	}
};
</script>

<style lang="scss" scoped>

</style>
